package com.mxf.code.strategy_factory.controller;

import com.mxf.code.strategy_factory.request.StatisticsRequest;
import com.mxf.code.strategy_factory.response.BaseResponse;
import com.mxf.code.strategy_factory.service.AnalysisTableService;
import com.mxf.code.strategy_factory.service.AnalysisTableStrategyContext;
import com.mxf.code.strategy_factory.service.FruitAnalysisTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author mxf
 * @version 1.0
 * @description: 统计分析
 * @date 2023/5/26
 */
@RestController
@RequestMapping("statistical/indicators")
public class StatisticalIndicatorsController {

    @Autowired
    private AnalysisTableStrategyContext analysisTableStrategyContext;
    @Autowired
    private FruitAnalysisTableService fruitAnalysisTableService;

    @GetMapping("listData")
    public List<BaseResponse> getListData(StatisticsRequest statisticsRequest) {
        AnalysisTableService resource = analysisTableStrategyContext.getResource(statisticsRequest.getStatisticalIndicatorsEnum());
        Assert.notNull(resource, "未知策略");
        return resource.getListData(statisticsRequest);
    }

    @GetMapping("chartData")
    public List<BaseResponse> getchartData(StatisticsRequest statisticsRequest) {
        AnalysisTableService resource = analysisTableStrategyContext.getResource(statisticsRequest.getStatisticalIndicatorsEnum());
        Assert.notNull(resource, "未知策略");
        return resource.getChartData(statisticsRequest);
    }

    @GetMapping("getFruitObtainInventory")
    public Double getFruitObtainInventory(StatisticsRequest statisticsRequest) {
        return fruitAnalysisTableService.getObtainInventory(statisticsRequest);
    }
}
